# Contributor: Mike Crute <mike@crute.us>
# Maintainer: Mike Crute <mike@crute.us>
pkgname=gerbera
pkgver=1.11.0
pkgrel=0
pkgdesc="A UPnP Media Server"
url="https://gerbera.io/"
arch="all"
license="GPL-2.0-or-later"
makedepends="
	cmake
	samurai
	curl-dev
	duktape-dev
	e2fsprogs-dev
	exiv2-dev
	ffmpeg-dev
	ffmpegthumbnailer-dev
	file-dev
	fmt-dev
	gnu-libiconv-dev
	gtest-dev
	inotify-tools-dev
	libebml-dev
	libexif-dev
	libmatroska-dev
	libupnp-dev
	pugixml-dev
	spdlog-dev
	sqlite-dev
	taglib-dev
	zlib-dev
	"
checkdepends="gmock"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-openrc"
pkgusers="$pkgname"
pkggroups="$pkgname"
#
# Patches
#
# disable-git-test.patch:
#	Patch removes check for git info in server version output. This assumes
#	that the binary was built within a git repo which is not the case for
#	releases. This test will never work for us.
# 32-bit-fix.patch:
#	temp fixes for 32-bit tests
#
source="gerbera-$pkgver.tar.gz::https://github.com/gerbera/gerbera/archive/v$pkgver.tar.gz
	disable-git-test.patch
	32-bit-fix.patch
	$pkgname.initd
	$pkgname.confd"

build() {
	cmake -B build -G Ninja \
		-Wno-dev \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DWITH_MAGIC=1 \
		-DWITH_MYSQL=0 \
		-DWITH_CURL=1 \
		-DWITH_INOTIFY=1 \
		-DWITH_JS=1 \
		-DWITH_TAGLIB=1 \
		-DWITH_AVCODEC=1 \
		-DWITH_FFMPEGTHUMBNAILER=1 \
		-DWITH_EXIF=1 \
		-DWITH_EXIV2=1 \
		-DWITH_MATROSKA=1 \
		-DWITH_SYSTEMD=0 \
		-DWITH_LASTFM=0 \
		-DWITH_DEBUG=0 \
		-DWITH_TESTS=1
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	"$builddir/build"/gerbera --create-config > config.xml
	sed -i 's#<home>.*#<home>/var/lib/gerbera</home>#' config.xml

	install -dm750 -o $pkgusers -g $pkggroups \
		"$pkgdir/var/lib/$pkgname" \
		"$pkgdir/var/log/$pkgname" \
		"$pkgdir/etc/$pkgname"
	install -m755 -D "$srcdir/$pkgname.initd" \
		"$pkgdir/etc/init.d/$pkgname"
	install -m644 -D "$srcdir/$pkgname.confd" \
		"$pkgdir/etc/conf.d/$pkgname"
	install -m644 -D "config.xml" \
		"$pkgdir/etc/$pkgname/config.xml"
}

sha512sums="
ae2b3342b3b57ce6d656d0ebadfd73b5f2764f2164314f6b0deac170a82e6861349c37732e6914454918112124038b221dbd4882001b5de51a49326432ccd70f  gerbera-1.11.0.tar.gz
5f084b107a534e8d8debda6fbc494ed7ab5d38e6de3d85867f2c316bd3f7d56daf3755de2647be84ae514905f998dad83ac88736a6ca59a30560c3d7a98dffcb  disable-git-test.patch
6be3eb807b64e66397eab587ff28b1bfb6f2b369902bab85bbe0509f1c8a3ec4687855ee174ee5aa5955cb10731fd1c28ed6aad605fc0d5ffa258b6ed2c9d3d2  32-bit-fix.patch
b8609b8ec46d8e61087b76ea9be34639786014f6545a2eb8dae977e56dcc3841715c0691417382d93d96eefd4c5a629e46cd9605c893445a66ac2815ec141c2b  gerbera.initd
392d7e964b0328778847f871e88ffd475ddac99b6cf8c8ded4825eb2f970e084db692552790a1b30ff96f59eabcd9fff50164d9dedf328badab95a1cec833c02  gerbera.confd
"
